package com.nit.jap.base;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * @author :fjw
 * @description:Repository基类
 * @date :2020/10/15 21:47
 */
@NoRepositoryBean
public interface BaseRepository<T extends BaseEntity, ID extends Serializable> extends JpaRepository<T, ID> {
	/**
	 * 通用逻辑删除
	 * 实体主键字段用id如：
	 *
	 * @param ids
	 * @return Integer
	 * @Id
	 * @Column(name = "dept_id")
	 * @NotNull(groups = BaseEntity.Update.class)
	 * @ApiModelProperty(value = "ID", hidden = true)
	 * @GeneratedValue(strategy = GenerationType.IDENTITY)
	 * private Long id;
	 */
	@Modifying
	@Query("update #{#entityName} e set e.isDel = 1 where e.id in :ids")
	@Transactional
	Integer deleteLogic(@Param("ids") List<Long> ids);

}
